﻿<inter:PluginConfigForm x:Class="Convertor.Plugin.InputAndOutput.ConfigForm"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:sm="clr-namespace:Wpf.CommonTools.SystemExtension;assembly=Wpf.CommonTools"
             xmlns:conv="clr-namespace:Wpf.CommonTools.Converter;assembly=Wpf.CommonTools"
             xmlns:local="clr-namespace:Convertor.Plugin.InputAndOutput"
             xmlns:inter="clr-namespace:Convertor.Interface;assembly=Convertor.Interface"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             mc:Ignorable="d">
    <inter:PluginConfigForm.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Convertor;component\Assets\Style.xaml"/>
                <ResourceDictionary Source="Assets\Lang\StringResource.zh.xaml"/>
                <ResourceDictionary Source="Assets\Lang\StringResource.en.xaml"/>
            </ResourceDictionary.MergedDictionaries>
                        <conv:FindUILanguageConverter x:Key="FindUILanguageConverter"/>
            <conv:EnumToVsibleConverter x:Key="EnumToVsibleConverter"/>
            <conv:EnumHasFlagMultiConverter x:Key="EnumHasFlagMultiConverter"/>
            <conv:EnumToIntConverter x:Key="EnumToIntConverter"/>
            <conv:EnumFlagToVsibleConverter x:Key="EnumFlagToVsibleConverter"/>

            <local:Plugin x:Key="Plugin"/>
            <local:OperateTargetSourceConverter x:Key="OperateTargetSourceConverter"/>
            
            <ObjectDataProvider x:Key="OperateTarget" 
                        MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
                <ObjectDataProvider.MethodParameters>
                    <x:Type TypeName="inter:OutputTypes"/>
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
            <ObjectDataProvider x:Key="OperateInputTypes" 
                        MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
                <ObjectDataProvider.MethodParameters>
                    <x:Type TypeName="local:OperateInputTypes"/>
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
            <ObjectDataProvider x:Key="OperateOutputTypes" 
                        MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
                <ObjectDataProvider.MethodParameters>
                    <x:Type TypeName="local:OperateOutputTypes"/>
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
            <ObjectDataProvider x:Key="CompareTypes" 
                        MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
                <ObjectDataProvider.MethodParameters>
                    <x:Type TypeName="local:CompareTypes"/>
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
        </ResourceDictionary>
    </inter:PluginConfigForm.Resources>
    <DockPanel MinWidth="500" MaxWidth="800" 
               DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type inter:PluginConfigForm}}, Path=Config}">
        <AdornerDecorator DockPanel.Dock="Top">
            <ComboBox x:Name="cbOperateTarget"
                      ItemsSource="{Binding Source={StaticResource OperateTarget}}"
                      SelectedItem="{Binding Path=OperateTarget}" >
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=., Converter={StaticResource FindUILanguageConverter}, ConverterParameter=''}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
                <sm:WatermarkService.Titlemark>
                    <TextBlock Text="{DynamicResource Plugin_InputAndOutput_OperateTarget}" TextAlignment="Right"></TextBlock>
                </sm:WatermarkService.Titlemark>
            </ComboBox>
        </AdornerDecorator>
        <AdornerDecorator DockPanel.Dock="Top">
            <ComboBox x:Name="cbOperateTypes"
                      ItemsSource="{Binding ElementName=cbOperateTarget, Path=SelectedItem, Converter={StaticResource OperateTargetSourceConverter}, Mode=OneWay}"
                      SelectedItem="{Binding Path=OperateType}" >
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=Name, Converter={StaticResource FindUILanguageConverter}, ConverterParameter='Plugin_InputAndOutput_OperateType_'}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
                <sm:WatermarkService.Titlemark>
                    <TextBlock Text="{DynamicResource Plugin_InputAndOutput_OperateTypes}" TextAlignment="Right"></TextBlock>
                </sm:WatermarkService.Titlemark>
            </ComboBox>
        </AdornerDecorator>
        <AdornerDecorator DockPanel.Dock="Top"
                          Visibility="{Binding ElementName=cbOperateTypes, Path=SelectedItem.Value, Converter={StaticResource EnumToVsibleConverter}, ConverterParameter=2}">
            <TextBox AcceptsReturn="True" AcceptsTab="True" MinHeight="50"
                     Text="{Binding Path=OperateText, UpdateSourceTrigger=PropertyChanged}">
                <sm:WatermarkService.Titlemark>
                    <TextBlock Text="{DynamicResource Plugin_InputAndOutput_OperateText}" TextAlignment="Right" VerticalAlignment="Bottom"></TextBlock>
                </sm:WatermarkService.Titlemark>
            </TextBox>
        </AdornerDecorator>
        <AdornerDecorator DockPanel.Dock="Top"
                          Visibility="{Binding ElementName=cbOperateTypes, Path=SelectedItem.Value, Converter={StaticResource EnumToVsibleConverter}, ConverterParameter=1}">
            <TextBox AcceptsReturn="True" AcceptsTab="True" MinHeight="50"
                 Text="{Binding Path=ReplaceText, UpdateSourceTrigger=PropertyChanged}">
                <sm:WatermarkService.Titlemark>
                    <TextBlock Text="{DynamicResource Plugin_InputAndOutput_ReplaceText}" TextAlignment="Right" VerticalAlignment="Bottom"></TextBlock>
                </sm:WatermarkService.Titlemark>
            </TextBox>
        </AdornerDecorator>
        <AdornerDecorator DockPanel.Dock="Top"
                          Visibility="{Binding ElementName=cbOperateTypes, Path=SelectedItem.Value, Converter={StaticResource EnumFlagToVsibleConverter}, ConverterParameter=96}">
            <TextBox Text="{Binding Path=UniqName, UpdateSourceTrigger=PropertyChanged}">
                <sm:WatermarkService.Titlemark>
                    <TextBlock Text="{DynamicResource Plugin_InputAndOutput_UniqName}" TextAlignment="Right" VerticalAlignment="Bottom"></TextBlock>
                </sm:WatermarkService.Titlemark>
            </TextBox>
        </AdornerDecorator>
        <AdornerDecorator DockPanel.Dock="Top"
                          Visibility="{Binding ElementName=cbOperateTypes, Path=SelectedItem.Value, Converter={StaticResource EnumToVsibleConverter}, ConverterParameter=16}">
            <ListBox ItemsSource="{Binding Source={StaticResource CompareTypes}}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <CheckBox
                                    Checked="CheckBox_Checked"
                                    Unchecked="CheckBox_Unchecked"
                                    Tag="{Binding Path=.}" 
                                    Content="{Binding Path=., Converter={StaticResource FindUILanguageConverter}, ConverterParameter='Plugin_InputAndOutput_CompareTypes_'}">
                                <CheckBox.IsChecked>
                                    <MultiBinding Converter="{StaticResource EnumHasFlagMultiConverter}" Mode="OneWay">
                                        <Binding Path="Config.CompareType" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type inter:PluginConfigForm}}"/>
                                        <Binding Path="."/>
                                    </MultiBinding>
                                </CheckBox.IsChecked>
                            </CheckBox>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <sm:WatermarkService.Titlemark>
                    <TextBlock Text="{DynamicResource Plugin_InputAndOutput_CompareType}" TextAlignment="Right" VerticalAlignment="Bottom"></TextBlock>
                </sm:WatermarkService.Titlemark>
            </ListBox>
        </AdornerDecorator>
        <TextBlock Style="{StaticResource InfoStyle}" DockPanel.Dock="Top" Text="{Binding Path=ToolTip}"/>
    </DockPanel>
</inter:PluginConfigForm>
